import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class BibliotecaApp {

    private Menu menu= new Menu();
    private Library library;
    private UserDataBase userDataBase;
    private HashMap<String,Command> commands;


    public BibliotecaApp(Menu menu, Library library,UserDataBase userDataBase){
        this.library = library;
        this.menu = menu;
        this.userDataBase = userDataBase;
        commands = new HashMap<String, Command>();
        commands.put("1",new ViewCommand(library));
        commands.put("2",new ReserveCommand(library,menu,userDataBase));
        commands.put("3",new MembershipCommand(library,menu,userDataBase));
        commands.put("4",new MovieCommand(library));
        //commands.put("5", new QuitCommand());
    }

    public static void main(String[] args) {

        ArrayList<LibraryItem> bookList= new ArrayList<LibraryItem>();
        ArrayList<LibraryItem> movieList = new ArrayList<LibraryItem>();

        Menu menu1 = new Menu();
        User user = new User("111-1111","Bill","password","bill@thoughtworks.com","876-888-2272");
        UserDataBase userDataBase1 = new UserDataBase("111-1111",user);

        bookList.add(new Book("GoldFish"));
        bookList.add(new Book("Run"));
        movieList.add(new Movie("The Hobbit", "2012", "Peter Jackson", "10"));
        movieList.add(new Movie("Pans Labrynth", "2010", "Sophie Krisch", "9"));
        movieList.add(new Movie("Harry Potter", "2007", "Stacey Watro", "8"));
        movieList.add(new Movie("Casablanca", "1939", "Humphrey Bogart", "10"));
        movieList.add(new Movie("Up", "2011", "Old Man", "9"));
        movieList.add(new Movie("Clue", "1975", "Professor Plum", "2"));
        movieList.add(new Movie("Snake on a Plane", "2006", "Samuel L. Jackson", "1"));
        movieList.add(new Movie("Superman", "1960", "Christopher Reeve", "N/A"));
        movieList.add(new Movie("Into the Wild", "2009", "Sophie Krisch", "8"));
        movieList.add(new Movie("Pitch Perfect", "2012", "Fat Amy", "7"));
        movieList.add(new Movie("Zero Dark Thirty", "2012", "Jessica Chastain", "9"));
        movieList.add(new Movie("Argo", "2012", "Ben Afflec", "8"));
        movieList.add(new Movie("Sleeping Beauty", "1960", "The Prince", "5"));
        movieList.add(new Movie("Snow White", "1950", "Grumpy", "7"));
        movieList.add(new Movie("The Lion King", "1985", "Mufasa", "10"));
        Library library1 = new Library(bookList,movieList);




        BibliotecaApp app = new BibliotecaApp(menu1,library1,userDataBase1);
        app.menu.welcomeMessage();
        while(true){
        app.menu.printMenuOptions();
        String instruction = app.menu.selectMenuOption();
        app.actionPerformed(instruction);
        }

    }

    public void actionPerformed(String instruction){
        commands.get(instruction).select();
    }
}
